USE [CTEM-DB-v1]
GO

/****** Object:  StoredProcedure [dbo].[Employee_DeleteSalaryByEmployeeIDAndMonth]    Script Date: 02/10/2012 11:26:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Hainh
-- Create date: 27/12/2011

-- =============================================
CREATE PROCEDURE [dbo].[Employee_DeleteSalaryByEmployeeIDAndMonth]
            @EmployeeID		BIGINT,
	        @Month			VARCHAR(50)
AS	        
BEGIN
	DECLARE @GenerateDebt BIGINT,
	        @SalaryId     BIGINT
	
	SELECT	@GenerateDebt = GenerateDebt, @SalaryId = E.EmployeeSalaryID
	FROM	EmployeeSalary E
	WHERE	E.EmployeeID = @EmployeeID and   E.Month = @Month
    DELETE  FROM EmployeeSalary
    WHERE   EmployeeSalaryID = @SalaryId
	UPDATE	Employee
	SET		TotalDebt = TotalDebt - @GenerateDebt
	WHERE	EmployeeID = @EmployeeID
END

GO

